package com.smmisia.shop.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

import com.smmisia.shop.constant.ProductEvent;
import com.smmisia.shop.constant.ProductStateEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 
 * @TableName product_inventory_stream
 */
@TableName(value ="product_inventory_stream")
@Data
@AllArgsConstructor
public class ProductInventoryStream implements Serializable {
    /**
     * 主键ID（自增主键）
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 商品id
     */
    private Long productId;

    /**
     * 本次变更的数量
     */
    private Long changedQuantity;

    /**
     * 价格
     */
    private BigDecimal price;

    /**
     * 商品数量
     */
    private Long quantity;

    /**
     * 详情
     */
    private String detail;

    /**
     * 可销售库存
     */
    private Long saleableInventory;

    /**
     * 幂等号
     */
    private String identifier;

    /**
     * 已占用库存
     */
    private Long occupiedInventory;

    /**
     * 状态
     */
    private ProductStateEnum state;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 流水类型
     */
    private ProductEvent streamType;

    /**
     * 逻辑删除，0为未删除，非0为已删除
     */
    private Integer deleted;

    /**
     * 乐观锁版本
     */
    private Integer lockVersion;

    /**
     * 创建者
     */
    private Integer creatorId;

    /**
     * 修改时间
     */
    private LocalDateTime updateTime;

    /**
     * 扩展信息
     */
    private String extendInfo;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        ProductInventoryStream other = (ProductInventoryStream) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getProductId() == null ? other.getProductId() == null : this.getProductId().equals(other.getProductId()))
            && (this.getChangedQuantity() == null ? other.getChangedQuantity() == null : this.getChangedQuantity().equals(other.getChangedQuantity()))
            && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice()))
            && (this.getQuantity() == null ? other.getQuantity() == null : this.getQuantity().equals(other.getQuantity()))
            && (this.getDetail() == null ? other.getDetail() == null : this.getDetail().equals(other.getDetail()))
            && (this.getSaleableInventory() == null ? other.getSaleableInventory() == null : this.getSaleableInventory().equals(other.getSaleableInventory()))
            && (this.getIdentifier() == null ? other.getIdentifier() == null : this.getIdentifier().equals(other.getIdentifier()))
            && (this.getOccupiedInventory() == null ? other.getOccupiedInventory() == null : this.getOccupiedInventory().equals(other.getOccupiedInventory()))
            && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
            && (this.getStreamType() == null ? other.getStreamType() == null : this.getStreamType().equals(other.getStreamType()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
            && (this.getLockVersion() == null ? other.getLockVersion() == null : this.getLockVersion().equals(other.getLockVersion()))
            && (this.getCreatorId() == null ? other.getCreatorId() == null : this.getCreatorId().equals(other.getCreatorId()))
            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
            && (this.getExtendInfo() == null ? other.getExtendInfo() == null : this.getExtendInfo().equals(other.getExtendInfo()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getProductId() == null) ? 0 : getProductId().hashCode());
        result = prime * result + ((getChangedQuantity() == null) ? 0 : getChangedQuantity().hashCode());
        result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode());
        result = prime * result + ((getQuantity() == null) ? 0 : getQuantity().hashCode());
        result = prime * result + ((getDetail() == null) ? 0 : getDetail().hashCode());
        result = prime * result + ((getSaleableInventory() == null) ? 0 : getSaleableInventory().hashCode());
        result = prime * result + ((getIdentifier() == null) ? 0 : getIdentifier().hashCode());
        result = prime * result + ((getOccupiedInventory() == null) ? 0 : getOccupiedInventory().hashCode());
        result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getStreamType() == null) ? 0 : getStreamType().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getLockVersion() == null) ? 0 : getLockVersion().hashCode());
        result = prime * result + ((getCreatorId() == null) ? 0 : getCreatorId().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getExtendInfo() == null) ? 0 : getExtendInfo().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", productId=").append(productId);
        sb.append(", changedQuantity=").append(changedQuantity);
        sb.append(", price=").append(price);
        sb.append(", quantity=").append(quantity);
        sb.append(", detail=").append(detail);
        sb.append(", saleableInventory=").append(saleableInventory);
        sb.append(", identifier=").append(identifier);
        sb.append(", occupiedInventory=").append(occupiedInventory);
        sb.append(", state=").append(state);
        sb.append(", createTime=").append(createTime);
        sb.append(", streamType=").append(streamType);
        sb.append(", deleted=").append(deleted);
        sb.append(", lockVersion=").append(lockVersion);
        sb.append(", creatorId=").append(creatorId);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", extendInfo=").append(extendInfo);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    public ProductInventoryStream(Product product, String identifier, ProductEvent streamType, Long quantity) {
        this.productId = product.getId();
        this.price = product.getPrice();
        this.quantity = product.getQuantity();
        this.saleableInventory = product.getSaleableInventory();
        this.occupiedInventory = product.getOccupiedInventory();
        this.state = product.getState();
        this.streamType = streamType;
        this.identifier = identifier;
        this.changedQuantity = quantity;
        this.setLockVersion(product.getLockVersion());
        this.setDeleted(product.getDeleted());
    }
}